<?php if(empty($_SESSION)){session_start();}
header("Content-Type: text/html; charset=utf-8" , true);

include_once("../../includes/restrito.php");include_once("../models/cls.edicao.php");

$oEdicao = new edicao();$ano = date("Y");
if( ! empty( $_GET ) )
{	$acao = $_GET["acao"];	
	
	switch( $acao )
	{		case "editar" :			$oEdicao->select( $_GET["id"] );			break;					case "excluir" :			$oEdicao->delete( $_GET["id_delete"] , "../views/frm.edicao.lista.php" , 'excluscao_logica' );			break;	
		case "especial_ativar" :			$oEdicao->especial( $_GET["id"] , $acao );			break;	
		case "especial_desativar" :			$oEdicao->especial( $_GET["id"] , $acao );			break;	
		case "publicar" :			$oEdicao->publicar( $_GET["id"] , $_GET["id_idioma"] );			break;	
		case "dataFilter" :			$dataFilter = $_GET["ano"];			break;
	}}?><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>EDIÇÃO</title><link rel="stylesheet" type="text/css" href="../../includes/sistema.css"/><script type="text/javascript" src="../../includes/jquery.js"></script><script type="text/javascript" src="../../includes/jquery.mask.js"></script><script>$(function(){	$("#ano").mask("9999");	$("#data").mask("99/99/9999");});
function _lixeira(id){	if(confirm("Por favor, confirme esta ação!"))	{		window.location.href="frm.edicao.lista.php?id_delete=" + id + "&acao=excluir";	}	}
function _dataFilter(ano){	window.location.href="frm.edicao.lista.php?ano=" + ano + "&acao=dataFilter";}
function _salvar(){	if(document.frm.publicar.checked)	{		document.frm.publicar.value = 1;	}	else	{		document.frm.publicar.value = 0;	}	if(document.frm.especial.checked)	{		document.frm.especial.value = 1;	}	else	{		document.frm.especial.value = 0;	}	if(document.frm.id_idioma.value=="")	{		alert("Por favor, informe o idioma desta edição!");		document.frm.id_idioma.focus();		return;	}	if(document.frm.ano.value=="")	{		alert("Por favor, informe o ano desta edição!");		document.frm.ano.focus();		return;	}	if(document.frm.data.value=="")	{		alert("Por favor, informe a data desta edição!");		document.frm.data.focus();		return;	}	if(document.frm.nome.value=="")	{		alert("Por favor, informe o título desta edição!");		document.frm.nome.focus();		return;	}	document.frm.submit();}</script></head>
<body><div id="content">    <form name="frm" method="post" action="../controllers/ctl.edicao.php">    <table width="100%" border="0">      <tr>        <td width="31%"><h1>Edições de <?php if( empty( $dataFilter )){ echo $ano; } else { echo $dataFilter; } ?></h1></td>        <td width="59%" align="center"><div style="text-align:center;padding:10px;"> Exibir por:          <select name="data_filter" class="form70px" onchange="_dataFilter(this.value)">            <?php echo $oEdicao->select_data_filter(); ?>          </select>        </div></td>        <td width="10%" align="center"><a href="frm.edicao.lixeira.php"><img src="../imagens/lixeira.grande.png" width="50" height="50" border="0" /><br />          Lixeira</a></td>      </tr>    </table>    <hr size="1" noshade="noshade">    <?php
    $cor = true;	if( empty( $dataFilter ) )
	{
		$aEdicao = $oEdicao->select_edicao( $ano );
	}
	else{
		$aEdicao = $oEdicao->select_edicao( $dataFilter );
	}
	echo '<table width=100%>';
	echo '<th align="left">TÍTULO</th>';
	echo '<th align="center">ORDENAR CAPA</th>';
	echo '<th align="center">PUBLICAR</th>';
	echo '<th align="center">IDIOMA</th>';
	echo '<th align="center">ANO</th>';
	echo '<th align="center">DATA</th>';
	echo '<th align="center">ESPECIAL</th>';
	echo '<th align="center">EDITAR</th>';
	echo '<th align="center">LIXEIRA</th>';
	
	foreach( $aEdicao as $sItem )	{		if($cor)		{			$tdcor = "#F4F4F4";			$cor=false;		}		else{			$tdcor = "#FFFFFF";			$cor = true;		}	
		$_SESSION["id_revista"] = $sItem['id'];	
		echo '<tr bgcolor="'. $tdcor .'">';		echo '<td align="left"><a href="frm.edicao.controle.php?id=' . $sItem['id'] . '&nome=' . $sItem['nome'] . '">' . $sItem['nome'] . '</a></td>';		if($sItem['publicar'] == 1){
			echo '<td width="10%" align="center"><a href="frm.capa.php?id=' . $_SESSION["id_revista"] . '"><img src="../imagens/capa.png" border="0" title="Ordenar matéria"></a></td>';
			echo '<td width="10%" align="center"><img src="../imagens/planeta.png" border="0" title="Edição publicada"></td>';		}
		else{
			echo '<td width="10%" align="center"><a href="frm.capa.php?id=' . $_SESSION["id_revista"] . '"><img src="../imagens/capa.png" border="0" title="Ordenar matéria"></a></td>';
			echo '<td width="10%" align="center"><a href="frm.edicao.lista.php?id=' . $sItem["id"] . '&id_idioma=' . $sItem["id_idioma"] . '&acao=publicar"><img src="../imagens/planeta.out.png" border="0" title="Edição não publicada"></a></td>';		}	
		$sigla = $sItem["sigla"];
		
		switch( $sigla )
		{			case "BR" :
				$icon = "br.gif";
				break;	
			case "ES" :
				$icon = "es.gif";
				break;	
			case "FR" :
				$icon = "fr.gif";
				break;	
			case "DE" :
				$icon = "de.gif";
				break;	
			case "US" :
				$icon = "us.gif";
				break;	
			case "NL" :
				$icon = "nl.gif";
				break;	
			case "IT" :
				$icon = "it.gif";
				break;	
			default :
				$icon = "world.gif";
				break;
		}	
		echo '<td width="10%" align="center"><img src="../imagens/' . $icon . '" border="0"></td>';
		echo '<td width="10%" align="center">' . $sItem["ano"] . '</td>';
		echo '<td width="10%" align="center">' . $oEdicao->formatar_data( $sItem["data"] , 'get' ) . '</td>';	
		if($sItem["especial"] == 0)
		{
			echo '<td width="10%" align="center"><a href="frm.edicao.lista.php?id=' . $sItem["id"] . '&acao=especial_ativar" title="Ativar Especial"><img src="../imagens/ativar.out.png" border="0"></a></td>';
		}
		else
		{
			echo '<td width="10%" align="center"><a href="frm.edicao.lista.php?id=' . $sItem["id"] . '&acao=especial_desativar" title="Desativar Especial"><img src="../imagens/ativar.png" border="0"></a></td>';		}		
		echo '<td width="10%" align="center"><a href="frm.edicao.php?id=' . $sItem["id"] . '&acao=editar"><img src="../imagens/editar.png" border="0" title="Editar"></a></td>';
		echo '<td width="10%" align="center"><a href="javascript:_lixeira(' . $sItem["id"] . ');"><img src="../imagens/lixeira.png" border="0" title="Lixeira"></a></td>';	
		echo '</tr>';
	}
	echo '</table>';
	?>
<div style="text-align:center; padding:10px;">
<input type="button" value="NOVA EDIÇÃO" class="formButton" onclick="javascript:window.location.href='frm.edicao.php';" />
</div>
</form>
</div>
</body>
</html>